#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
开放商户 - 进件取消功能使用示例
"""

import os
import sys

# 添加项目根目录到Python路径，确保能够导入jlpay包
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))

from examples.base_example import BaseExample
from jlpay.services.openmerch.register.incoming_cancel_service import IncomingCancelService
from jlpay.model.openmerch.register.incoming_cancel import IncomingCancelRequest


class IncomingCancelExample(BaseExample):
    """进件取消示例类"""
    
    def __init__(self):
        """初始化示例类"""
        super().__init__("examples.openmerch.register.incoming_cancel")
        # 创建进件取消服务
        self.service = IncomingCancelService(self.config)
    
    def demo(self):
        """执行进件取消示例"""
        self.logger.info("开始执行进件取消示例")
        
        # 创建进件取消请求
        request = self.build_incoming_cancel_request()
        
        # 发送请求并处理响应
        response = self.send_request_and_handle_response(
            self.service.cancel_incoming,
            "进件取消",
            request
        )
        
        # 处理响应结果
        if response and response.is_success():
            self.logger.info(f"响应报文：{response.to_dict()}")
        
        self.logger.info("进件取消示例执行完毕")
    
    def build_incoming_cancel_request(self):
        """构建进件取消请求"""
        request = IncomingCancelRequest()
        
        # 设置请求参数
        request.set_apply_id("lcy_incoming_uat_20250630_0001")
        
        return request


if __name__ == "__main__":
    logger = IncomingCancelExample().logger
    logger.info("=" * 50)
    logger.info("===== 进件取消示例 开始 =====")
    logger.info("=" * 50)
    
    example = IncomingCancelExample()
    example.demo()
    
    logger.info("=" * 50)
    logger.info("===== 进件取消示例执行完毕 =====")
    logger.info("=" * 50) 